<?php
session_start();
function mysqlConnect_PHP(){
		include('../config/config.inc.php');	
		$db = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
		$db_select = mysql_select_db($mysql_dbname, $db);	
}

function getDBrow($username, $dbname)
{
	if(empty($username))
		return 0;
	else
	{
		mysqlConnect_PHP();
		$query = "SELECT * FROM ".$dbname." WHERE username='".$username."';";
		$result = mysql_query($query);
		while($res = mysql_fetch_array($result))
		{
			return $res;
		}	
	}
}
$infos=getDBrow($_SESSION['username'], 'accounts');
if($infos['admin'] == 1)
{
	if(isset($_POST['password']) && isset($_POST['username']))
	{
		mysqlConnect_PHP();	
		$password = md5($_POST['password']);
		mysql_query("UPDATE accounts set password='".$password."' where username='".$_POST['username']."';");
		echo "Passwort erfolgreicht ge&auml;ndert zu:  ".$_POST['password']." (".$password.")";
	}
	?>
	<head>
		<title>MyBook+</title>
		<link rel="icon" href="../favicon.ico" type="image/x-icon" /> 
		<meta name="description" content="Das beste Social Network der Welt" content="text/html; utf-8"/>
	</head>
	<div style="float: left; height: 50px; width: 100%; background: #303030; margin-bottom: 20px; box-shadow: 0 0 10px 1px #505050; "><a href="./index.php"><img src="./back.png"/ style="float: left; height: 50px; width: 82px; "></a>
		<h1 style="float: left; margin: 6px 0 0 30px; color: #f0f0f0;"> Development - Passwort &auml;ndern</h1>
	</div>
	<form method="post" action="">
		Username: <input type="text" name="username">
		Password: <input type="text" name="password">
		<input type="submit" value="absenden">
	</form>
<?php
}
?>